package com.kuang.demo.service;

import com.kuang.demo.bo.gh.CreateCategoryBO;
import com.kuang.demo.bo.gh.DeleteCategoryBO;
import com.kuang.demo.bo.gh.UpdateCategoryBO;
import com.kuang.demo.mapper.CategoryMapper;
import com.kuang.demo.pojo.CategoryVO;
import com.kuang.demo.vo.QueryCategoryL1VO;
import com.kuang.demo.vo.QueryCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 郭浩 on 2020/11/2 10:05
 */
@Service
public class CategoryServiceImpl implements CategoryService{
    @Autowired
    CategoryMapper categoryMapper;
    @Override
    public List<QueryCategoryVO.DataBean> queryList() {
        return categoryMapper.queryCategory();
    }

    @Override
    public List<QueryCategoryL1VO.DataBean> queryL1List() {
        return categoryMapper.queryL1Category();
    }

    @Override
    public CategoryVO createCategory(CreateCategoryBO createCategoryBO) {
        categoryMapper.insertCategory(createCategoryBO);
        int id = createCategoryBO.getId();
        CategoryVO categoryVO = categoryMapper.queryCategoryById(id);
        return categoryVO;
    }

    @Override
    public void updateCategoey(UpdateCategoryBO updateCategoryBO) {
        categoryMapper.updateCategory(updateCategoryBO);
    }

    @Override
    public void deleteCategory(DeleteCategoryBO deleteCategoryBO) {
        categoryMapper.deleteCategoryL1(deleteCategoryBO.getId());
        if (deleteCategoryBO.getChildren() != null){
            categoryMapper.deleteCategoryL2(deleteCategoryBO.getChildren());
        }
    }
}
